package com.ruoyi.oos.web.controller.overrun;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.oos.duty.domain.DutyTeam;
import com.ruoyi.oos.overrun.domain.OverrunRecord;

/**
 * 超限基础控制类
 * @author Administrator
 *
 */
public class OverrunController extends BaseController {

	/**
	 * 处理图形显示数据.
	 * @param list1
	 * @param list2
	 * @param dutylist
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public Map<String, Object> handleChartsData(List<OverrunRecord> list1, List<OverrunRecord> list2, List<DutyTeam> dutylist,
			String startDate, String endDate) {

  	List<Long> ydata1 = new ArrayList<Long>();
  	List<Long> ydata2 = new ArrayList<Long>();
  	List<String> xdata = new ArrayList<String>();
  	List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
  	Map<String, Object> map1 = new HashMap<String, Object>();
  	Map<String, Object> map2 = new HashMap<String, Object>();
  	
  	map1.put("tjdate", startDate);
  	map2.put("tjdate", endDate);
  	
  	long sum1 = 0;
  	long sum2 = 0;
  	long count1 = 0;
  	long count2 = 0;
  	
  	int i = 1;
  	for (DutyTeam team : dutylist) {
  		Long identify = team.getIdentify();
  		Long dutyid = team.getDutyId();
  		xdata.add(team.getName());
  		
  		long data1 = 0;
  		long cs1 = 0;
  		for (OverrunRecord record : list1) {
  			if (record.getDutyid() == dutyid && record.getIdentify() == identify) {
  				data1 = record.getTimes();
  				cs1 = record.getCounts();
  				break;
  			}
  		}
  		ydata1.add(data1);
  		sum1 += data1;
  		count1 += cs1;
  		
  		long data2 = 0;
  		long cs2 = 0;
  		for (OverrunRecord record : list2) {
  			if (record.getDutyid() == dutyid && record.getIdentify() == identify) {
  				data2 = record.getTimes();
  				cs2 = record.getCounts();
  				break;
  			}
  		}
  		ydata2.add(data2);
  		sum2 += data2;
  		count2 += cs2;
  		
  		map1.put("times"+i, data1);
    	map2.put("times"+i, data2);
    	map1.put("counts"+i, cs1);
    	map2.put("counts"+i, cs2);
    	i++;
  	}
  	
  	map1.put("times0", sum1);
  	map2.put("times0", sum2);
  	map1.put("counts0", count1);
  	map2.put("counts0", count2);
  	
  	list.add(map1);
  	list.add(map2);
  	
  	xdata.add(0, "合计");
  	ydata1.add(0, sum1);
  	ydata2.add(0, sum2);
  	
  	Map<String, Object> resMap = new HashMap<String, Object>();
  	resMap.put("xdata", xdata);
  	resMap.put("ydata1", ydata1);
  	resMap.put("ydata2", ydata2);
  	resMap.put("tjdate1", startDate);
  	resMap.put("tjdate2", endDate);
  	resMap.put("listdata", list);
  	
    return resMap;
	}
}
